package com.insurance.utils;

import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 阿里云发送信息工具类
 */
public class SendSmsUtils {
	
	private static final Logger log = LoggerFactory.getLogger(SendSmsUtils.class);

	private static final String accessKeyId = "LTAIa3ulRw8X8oUo";

	private static final String accessSecret = "jpuvlfYkzk9CGOR3bcqeT6hHT7yj8D";

//	private static final String templateCode = "SMS_168586066";

	private static final String smsUrl = "dysmsapi.aliyuncs.com";
	
	private static DefaultProfile profile = DefaultProfile.getProfile("default", accessKeyId, accessSecret);
	
	private static IAcsClient client = new DefaultAcsClient(profile);
	
	/**
	 * 发送信息
	 * @param phoneNumbers 手机号
	 * @param signName 签名
	 * @param templateCode 模板编码
	 * @param templateParam 模板传参
	 * @throws ClientException 
	 * @throws ServerException 
	 */
	public static void send(String phoneNumbers, String signName, String templateCode, String templateParam) throws ServerException, ClientException{
        CommonRequest request = new CommonRequest();
        request.setMethod(MethodType.POST);
        request.setDomain(smsUrl);
        request.setVersion("2017-05-25");
        request.setAction("SendSms");
        request.putQueryParameter("PhoneNumbers", phoneNumbers);
        request.putQueryParameter("SignName", signName);
        request.putQueryParameter("TemplateCode", templateCode);
        request.putQueryParameter("TemplateParam", templateParam);
        CommonResponse response = client.getCommonResponse(request);
        System.out.println("【发送信息响应报文："+response.getData()+"】");
	}
	
}
